var jump = {
    vector:null,
    provinceSource:null,
    citySource:null,
    countySource:null,
    rqSource:null,
    rqInfoSource:null,
    popup:null,
    countryPopVals:null,
    classSeries:null,
    classColors:null,
    selectVector:null,
    selectFeature:null,
    text:null,
    count:null,
    style:null,
    provinceId:null,
    cityId:null,
    countyId:null,
    rqId:null,
    rqInfoVector:null,
    rqInfoId:null,
    rqInfoCenter:null,
    rqInfoCount:null,
    init:function () {
        this.createPopup();
        this.style =  new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: 'rgba(55, 155, 205, 1)',
                width: 1
            }),
            text: new ol.style.Text({
                font: '10px sans-serif',
                text: "loading...",
                textAlign: 'center',
                rotateWithView: true,
                fill: new ol.style.Fill({
                    color: 'rgba(255, 255, 255, 1)'
                })
            })
        });
        this.vector = new ol.layer.Vector({
            source: this.getProvinceSource()
        })
        map.addLayer(this.vector);
        this.selectVector = new ol.layer.Vector({
            source: new ol.source.Vector()
        });
        map.addLayer(this.selectVector);
        var selectPointerMove = new ol.interaction.Select({
            condition: ol.events.condition.pointerMove
        });
        selectPointerMove.on('select', function (e) {
            var type = jump.vector.getSource().get('id');
            jump.onPointerMove(e, type);
        });
        map.addInteraction(selectPointerMove);
        map.on('singleclick', function (e) {
            jump.onPointerClick(e);
        });
        map.getView().on('change:resolution', function (e) {
            jump.onResChange(e);
        });
    },
    getProvinceSource:function () {
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                var url = '../../assets/newMap/data/mapdata/province.json';
                $.ajax({
                    url: url,
                    type: 'GET',
                    async: false,
                    success: function (data) {
                        var features = source.getFormat().readFeatures(data);
                        $.ajax({
                            url: '/newMap/initMapData',
                            type: 'POST',
                            async: false,
                            data: {
                                currentMap: 'clusterMap',
                                city: '-1',
                                level: '1'
                            },
                            success: function (info) {
                                var mapData = info.result.mapDataList;
                                var countryPopVals = new Array();
                                features.forEach(function (feature) {
                                    var count = jump.getProvinceCount(mapData, feature.N.id + '0000');
                                    countryPopVals.push(count);
                                    feature.set('type', 'province', false);
                                    feature.set('count', count, false);
                                });
                                jump.beginRender(countryPopVals);
                            }
                        });
                        source.addFeatures(features);
                    }
                })
            }
        });
        source.set('id', 'province');
        this.provinceSource = source;
        return source;
    },
    getCitySource:function (id) {
        var url = '../../assets/newMap/data/mapdata/city/'+ id + '.json';
        var source  = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                $.ajax({
                    url: url,
                    type: 'GET',
                    async: false,
                    success: function (data) {
                        var features = source.getFormat().readFeatures(data);
                        $.ajax({
                            url: '/newMap/initMapData',
                            type: 'POST',
                            async: false,
                            data: {
                                currentMap: 'clusterMap',
                                province: id + '0000',
                                level: '2'
                            },
                            success: function (info) {
                                var mapData = info.result.mapDataList;
                                var countryPopVals = new Array();
                                features.forEach(function (feature) {
                                    var count = jump.getProvinceCount(mapData, feature.N.id + '00');
                                    countryPopVals.push(count);
                                    feature.set('type', 'city', false);
                                    feature.set('count', count, false);
                                });
                                jump.beginRender(countryPopVals);
                            }
                        });
                        source.addFeatures(features);
                    }
                })
            }
        });
        source.set('id','city');
        this.citySource  = source;
        return source;
    },
    getCountySource:function (id) {
        var url = '../../assets/newMap/data/mapdata/county/' + id + '00.json';
        var source = new ol.source.Vector({
            id:'county',
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                $.ajax({
                    url: url,
                    type: 'GET',
                    async: false,
                    success: function (data) {
                        var features = source.getFormat().readFeatures(data);
                        $.ajax({
                            url: '/newMap/initMapData',
                            type: 'POST',
                            async: false,
                            data: {
                                currentMap: 'clusterMap',
                                city: id +'00',
                                level: '3',
                                district:'-1'
                            },
                            success: function (info) {
                                var mapData = info.result.mapDataList;
                                var countryPopVals = new Array();
                                features.forEach(function (feature) {
                                    var count = jump.getProvinceCount(mapData, feature.N.id);
                                    countryPopVals.push(count);
                                    feature.set('type', 'county', false);
                                    feature.set('count', count, false);
                                });
                                jump.beginRender(countryPopVals);
                            }
                        });
                        source.addFeatures(features);
                    }
                })
            }
        });
        source.set('id','county');
        this.countySource  = source;
        setTimeout(function () {
            map.render();
        },1);
        return source;
    },
    getRqSource: function (id) {
        var city = id.substring(0,4)+ '00';
        var url = '/map/mapCommunityData';
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                $.ajax({
                    url: url,
                    type: 'POST',
                    async: true,
                    data:{
                        currentMap: 'clusterMap',
                        city: city,
                        district:'-1'
                    },
                    success: function (data) {
                        var list = data.result.mapDataList;
                        var zoom = map.getView().getZoom();
                        var radius = 1e6 / Math.pow(2, zoom - 2.3);
                        var itemf = list[0];
                        var f = ol.proj.transform([itemf.lng, itemf.lat], 'EPSG:4326', 'EPSG:3857');
                        map.getView().setCenter(f);
                        list.forEach(function (item) {
                            var center = ol.proj.transform([item.lng, item.lat], 'EPSG:4326', 'EPSG:3857');
                            var feature = new ol.Feature({
                                id: item.communityId,
                                geometry: new ol.geom.Circle(center, radius),
                                text: item.communityName.replace(/\s/g, "") + '\n' + item.count + '笔'
                            });
                            feature.set('count', item.count, false);
                            feature.set('name',item.communityName.replace(/\s/g, ""),false);
                            feature.set('type', 'rq', false);
                            source.addFeature(feature);
                        })

                    }
                })
            }
        })
        source.set('id', 'rq', false);
        this.rqSource = source;
        setTimeout(function () {
            map.render();
        },1);
        return source;
    },
    getRqInfoSource: function (id, center) {
        var url = '/map/mapBuildingData';
        var source = new ol.source.Vector({
            format: new ol.format.GeoJSON({
                defaultDataProjection: 'EPSG:4326',
                featureProjection: 'EPSG:3857'
            }),
            loader: function (extent, resolution, projection) {
                $.ajax({
                    url: '/map/mapBuildingBankData2',
                    type: 'POST',
                    async: false,
                    data: {
                        city: jump.countyId + '00',
                        communityId: id,
                        district: '-1',
                        currentMap: 'clusterMap'
                    },
                    success: function (data) {
                        var hourseCount = data.result.community.totalHouseHoldCount;
                        var divList = jump.createRightDiv(jump.rqInfoName, hourseCount);
                        var overly = new ol.Overlay({
                            element: divList,
                            position: center,
                            positioning: 'bottom-right',
                            autoPan: true,
                            autoPanAnimation: {
                                duration: 250
                            }
                        })
                        map.addOverlay(overly);
                        var points = new Array();
                        var resultPoints = new Array()
                        var strPoint = $.trim(data.result.community.bound.slice(7).replace('((', '').replace('))', ''));
                        var point = strPoint.split(',');
                        point.forEach(function (point) {
                            var arrPoint = $.trim(point).split(' ');
                            var newArr = ol.proj.transform(arrPoint, 'EPSG:3857', 'EPSG:4326')
                            points.push(newArr);
                        })
                        resultPoints.push(points);
                        var jsonFeature = {
                            'type': 'Feature',
                            'geometry': {
                                'type': 'Polygon',
                                'coordinates': resultPoints
                            }
                        }
                        var feat = source.getFormat().readFeature(jsonFeature);
                        source.addFeature(feat);
                        feat.setStyle(new ol.style.Style({
                            stroke: new ol.style.Stroke({
                                color: 'red',
                                width: 1
                            })
                        }))
                        feat.set('info', 'rqBound')
                        var divList = jump.createDiv(data.result.mapDataList);
                        divList.forEach(function (item) {
                            var div = item[0];
                            var point = ol.proj.transform(item[1], 'EPSG:4326', 'EPSG:3857');
                            var overly = new ol.Overlay({
                                element: div,
                                position: point,
                                positioning: 'bottom-right',
                                autoPan: true,
                                autoPanAnimation: {
                                    duration: 250
                                }
                            })
                            map.addOverlay(overly);
                        })
                    }
                })
            }
        })
        source.set('id', 'rqInfo');
        this.rqInfoSource = source;
        setTimeout(function () {
            map.render();
        }, 1);
        return source;
    },
    getProvinceCount:function (mapData, id) {
        var count = 0;
        mapData.forEach(function (data) {
            if (id == data.zoneNumber) {
                count = data.count;
            }
        })
        return count;
    },
    beginRender: function (countryPopVals) {
        this.getAndSetClassesFromData(countryPopVals);
        this.vector.setStyle(this.setStyle);
    },
    getAndSetClassesFromData:function (data) {
        var colorFrom = 'DEE8EE';
        var colorTo = '006EE5';
        var serie = new geostats(data);
        serie.getClassEqInterval(5);
        var colors_x = chroma.scale([colorFrom, colorTo]).colors(5);
        serie.setColors(colors_x);
        jump.classSeries = serie;
        jump.classColors = colors_x;
    },
    setStyle: function (feat, res) {
        var currVal = parseFloat(feat.get("count"));
        var bounds = jump.classSeries.bounds;
        var numRanges = new Array();
        for (var i = 0; i < bounds.length - 1; i++) {
            numRanges.push({
                min: parseFloat(bounds[i]),
                max: parseFloat(bounds[i + 1])
            });
        }
        var classIndex = jump.verifyClassFromVal(numRanges, currVal);
        var polyStyleConfig = {
            stroke: new ol.style.Stroke({
                color: 'rgba(255, 0, 0,0.3)',
                width: 1
            })
        };
        var textStyleConfig = {};
        var label = feat.get('name');
        if (classIndex !== -1) {
            polyStyleConfig = {
                stroke: new ol.style.Stroke({
                    color: 'rgba(0, 0, 0, 0.5)', // 边框样式
                    width: 1
                }),
                fill: new ol.style.Fill({
                    color: jump.hexToRgbA(jump.classColors[classIndex], 0.7)
                })
            };
            textStyleConfig = {
                text: new ol.style.Text({
                    text: label,
                    font: '12px Calibri,sans-serif',
                    fill: new ol.style.Fill({
                        color: "#000000"
                    })
                    // ,
                    // stroke: new ol.style.Stroke({
                    //     color: "#000000",
                    //     width: 0
                    // })
                }),
                geometry: function (feature) {
                    var retPoint;
                    if (feature.getGeometry().getType() === 'MultiPolygon') {
                        retPoint = jump.getMaxPoly(feature.getGeometry().getPolygons()).getInteriorPoint();
                    } else if (feature.getGeometry().getType() === 'Polygon') {
                        retPoint = feature.getGeometry().getInteriorPoint();
                    }
                    return retPoint;
                }
            }
        };

        var textStyle = new ol.style.Style(textStyleConfig);
        var style = new ol.style.Style(polyStyleConfig);
        return [style, textStyle];
    },
    verifyClassFromVal: function (rangevals, val) {
        var retIndex = -1;
        for (var i = 0; i < rangevals.length; i++) {
            if (val >= rangevals[i].min && val <= rangevals[i].max) {
                retIndex = i;
            }
        }
        return retIndex;
    },
    hexToRgbA: function (hex, opacity) {
        var c;
        if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
            c = hex.substring(1).split('');
            if (c.length == 3) {
                c = [c[0], c[0], c[1], c[1], c[2], c[2]];
            }
            c = '0x' + c.join('');
            return 'rgba(' + [(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') + ',' + opacity + ')';
        }
        throw new Error('Bad Hex');
    },
    getMaxPoly: function (polys) {
        var polyObj = [];
        //now need to find which one is the greater and so label only this
        for (var b = 0; b < polys.length; b++) {
            polyObj.push({
                poly: polys[b],
                area: polys[b].getArea()
            });
        }
        polyObj.sort(function (a, b) {
            return a.area - b.area
        });

        return polyObj[polyObj.length - 1].poly;
    },
    setCircle: function (zoom) {
        if (this.vector.getSource() != null) {
            this.vector.getSource().forEachFeature(function (feature) {
                var geo = feature.getGeometry();
                if (geo.getType() == 'Circle') {
                    if (zoom < 14) {
                        geo.setRadius(1e6 / Math.pow(2, zoom - 2));
                    } else {
                        geo.setRadius(1e6 / Math.pow(2, zoom - 2.3));
                    }

                }
            })
        }
    },
    onResChange: function (e) {
        debugger
        var zoom = map.getView().getZoom();
        jump.vector.setStyle(jump.setStyle);
        if (zoom >= 5 && zoom < 7) {//省份
            if(jump.rqInfoVector != null){
                map.removeLayer(jump.rqInfoVector);
                jump.rqInfoVector = null;
            }
            jump.clearOverly();
            jump.vector.setSource(jump.getProvinceSource());
        } else if (zoom >= 7 && zoom < 9) { //市
            if(jump.rqInfoVector != null){
                map.removeLayer(jump.rqInfoVector);
                jump.rqInfoVector = null;
            }
            jump.clearOverly();
            jump.vector.setSource(jump.getCitySource(jump.cityId));
        } else if (zoom >= 9 && zoom < 14) { // 县
            if(jump.rqInfoVector != null){
                map.removeLayer(jump.rqInfoVector);
                jump.rqInfoVector = null;
            }
            jump.clearOverly();
            jump.vector.setSource(jump.getCountySource(jump.countyId));
        } else if (zoom >= 14 && zoom < 18) { // 小区
            if(jump.rqInfoVector != null){
                map.removeLayer(jump.rqInfoVector);
                jump.rqInfoVector = null;
            }
            jump.clearOverly();
            if (jump.rqSource != null) {
                jump.vector.setStyle(jump.style);
                jump.vector.setSource(jump.rqSource);
            }
        } else if (zoom >= 18) { // 小区详情
            if (jump.rqInfoVector != null) {
                var id = jump.rqInfoVector.get('id');
                if (id != jump.rqInfoId) {
                    map.removeLayer(jump.rqInfoVector);
                    jump.vector.setSource(new ol.source.Vector());
                    jump.rqInfoVector.getOverlays().clear();
                    jump.rqInfoVector = new ol.layer.Vector();
                    jump.rqInfoVector.set('id', jump.rqInfoId);
                    jump.rqInfoVector.setSource(jump.getRqInfoSource(jump.rqInfoId, jump.rqInfoCenter));
                    map.addLayer(jump.rqInfoVector);
                }
            }else{
                map.removeLayer(jump.rqInfoVector);
                jump.vector.setSource(new ol.source.Vector());
                jump.rqInfoVector = new ol.layer.Vector();
                jump.rqInfoVector.set('id', jump.rqInfoId);
                jump.rqInfoVector.setSource(jump.getRqInfoSource(jump.rqInfoId, jump.rqInfoCenter));
                map.addLayer(jump.rqInfoVector);
            }
        }
        jump.setCircle(zoom);
        jump.vector.getSource().refresh();
    },
    onPointerMove:function (e,type) {
        if (jump.selectFeature != null) {
            jump.selectVector.getSource().removeFeature(jump.selectFeature);
            jump.selectFeature = null;
        }
        if (type  != 'rq' && type != null) {
            jump.onCityMove(e);
        } else {
            jump.onRqMove(e);
        }
    },
    onCityMove:function (e) {
        var feature = e.selected[0];
        if (feature == null) {
            jump.hiddenOverly();
            return;
        }else {
            jump.showOverly();
        }
        var type = feature.get('type');
        var point = e.mapBrowserEvent.coordinate;
        jump.text = feature.N.name;
        jump.count = feature.get('count');
        jump.showInfo(point,jump.text,jump.count);
        jump.selectFeature = new ol.Feature({
            id: feature.N.id,
            geometry: feature.getGeometry()
        });
        jump.selectFeature.set('name',jump.text);
        jump.selectFeature.set('count',jump.count);
        var style = new ol.style.Style({
            stroke: new ol.style.Stroke({
                color: 'green',
                width: 1
            }),
            fill: new ol.style.Fill({
                color: 'rgba(221, 208, 0, 1)'
            }),
            text: new ol.style.Text({
                font: '12px',
                textAlign: 'center',
                rotateWithView: true,
                text:  jump.selectFeature.get('name'),
                fill: new ol.style.Fill({
                    color: 'rgba(255, 255, 255, 1)'
                })
            })
        });
        jump.selectFeature.setStyle(style);
        jump.selectFeature.set('type',type);
        jump.selectVector.getSource().addFeature(jump.selectFeature);
    },
    onRqMove:function (e) {
        var pixel = e.mapBrowserEvent.pixel;
        var features = [];
        map.forEachFeatureAtPixel(pixel, function (feature, layer) {
            if (layer != null) {
                if (layer.getVisible()) { // 当图层被隐藏之后,光标下该图层忽略
                    features.push(feature);
                }
            }
        });
        var len = features.length;
        var features_by_source;
        var zoom = map.getView().getZoom();
        if (len == 1 && zoom >= 12) {
            if(features[0].get('info') != null) {
                return;
            }
            var type = features[0].getGeometry().getType();
            var style = features[0].getStyle();
            if (type == 'Circle') {
                var text = features[0].getProperties().text;
                features[0].setStyle(jump.getSelectedPropertyStyle(type, text));
            } else {
                var featureArr = map.getLayers().getArray();
                var featureArr_len = featureArr.length;
                for (var j = 0; j < featureArr_len; j++) {
                    if (typeof featureArr[j].setStyle !== 'undefined') {
                        var source = featureArr[j].getSource();
                        features_by_source = source.getFeatures();

                        var feature_len = features_by_source.length;
                        for (var m = 0; m < feature_len; m++) {
                            if (typeof features_by_source[m].getProperties().text === 'undefined') {
                                text = 'none';
                            } else {
                                var text = features_by_source[m].getProperties().text
                            }
                            var type = features_by_source[m].getGeometry().getType();
                            var style = features_by_source[m].getStyle();
                            features_by_source[m].setStyle(jump.getUnselectedPropertyStyle(type, text, style, features_by_source[m]));
                        }
                    }
                }
            }
        }else{
            var featureArr = map.getLayers().getArray();
            var featureArr_len = featureArr.length;
            for (var j = 0; j < featureArr_len; j++) {
                if (typeof featureArr[j].setStyle !== 'undefined') {
                    var source = featureArr[j].getSource();
                    features_by_source = source.getFeatures();

                    var feature_len = features_by_source.length;
                    for (var m = 0; m < feature_len; m++) {
                        if (typeof features_by_source[m].getProperties().text === 'undefined') {
                            text = 'none';
                        } else {
                            var text = features_by_source[m].getProperties().text
                        }
                        var type = features_by_source[m].getGeometry().getType();
                        var style = features_by_source[m].getStyle();
                        if (features_by_source[m].get('info') == null) {
                            features_by_source[m].setStyle(jump.getUnselectedPropertyStyle(type, text, style, features_by_source[m]));
                        }
                    }
                }
            }
        }
    },
    onPointerClick:function (e) {
        var pixel = map.getEventPixel(e.originalEvent);
        var feature = map.forEachFeatureAtPixel(pixel, function (feature, layer) {
            return feature;
        });
        if (feature == null) {
            return;
        }
        if (jump.selectFeature != null) {
            jump.selectVector.getSource().removeFeature(jump.selectFeature);
            jump.selectFeature = null;
        }
        var extent = feature.getGeometry().getExtent();
        var center = ol.extent.getCenter(extent);
        var type = feature.get('type');
        var id = feature.N.id;
        var self = this;
        switch (type) {
            case 'province': {
                self.cityId = id;
                map.getView().setCenter(center);
                map.getView().setZoom(8);
                self.vector.setSource(self.getCitySource(id))
            }
                break;
            case 'city': {
                self.countyId = id;
                map.getView().setCenter(center);
                map.getView().setZoom(10);
                self.vector.setSource(self.getCountySource(id))
            }
                break;
            case 'county': {
                self.rqId = id;
                map.getView().setCenter(center);
                map.getView().setZoom(14);
                self.vector.setStyle(self.style);
                self.vector.setSource(self.getRqSource(id))
            }
                break;
            case 'rq': {
                self.rqInfoId = id;
                self.rqInfoCenter = center;
                self.rqInfoName = feature.get('name');
                self.rqInfoCount = feature.get('count');
                map.getView().setCenter(center);
                map.getView().setZoom(18);
            }
                break;
        }
    },
    getSelectedPropertyStyle: function (type, text) {
        var style = null;
        if (type == 'Circle') {
            style = new ol.style.Style({
                fill: new ol.style.Fill({
                    color: 'rgba(226, 74, 76, 1)',
                    opacity: '0.05'
                }),
                text: new ol.style.Text({
                    font: '10px',
                    textAlign: 'center',
                    rotateWithView: true,
                    text: text,
                    fill: new ol.style.Fill({
                        color: '#FFFFFF'
                    })
                })
            })
        }
        if (type == 'MultiPolygon' || type == 'Polygon') {
            style = new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'green',
                    width: 2
                }),
                fill: new ol.style.Fill({
                    color: 'rgba(76, 160, 101, 0.5)'
                })
            })
        }
        return style;
    },
    getUnselectedPropertyStyle: function (type, text, Style,feat) {
        var style = null;
        if (type == 'Point') { // 如果是点, 不去设置他的样式
            style = Style;
        }
        if (type == 'Circle') {
            var size = 5;
            var id =  jump.vector.getSource().get('id')
            var size =feat.get('count');
            if(size == null){
                size = 0;
            }
            var color = jump.getColorForId(id,size);
            style = new ol.style.Style({
                fill: new ol.style.Fill({
                    color: color,
                    opacity: '0.05'
                }),
                text: new ol.style.Text({
                    font: '10px',
                    textAlign: 'center',
                    rotateWithView: true,
                    text: text,
                    fill: new ol.style.Fill({
                        color: 'rgba(255, 255, 255, 1)'
                    })
                })
            })
        }
        if (type == 'MultiPolygon' || type == 'Polygon') {
            style = new ol.style.Style({
                stroke: new ol.style.Stroke({
                    color: 'rgba(55, 155, 205, 1)',
                    width: 1
                })
            })
        }
        return style;
    },
    getText: function (list, name, zoneNumber) {
        var result = new Array()
        var text , count;
        if (list.length == 0) {
            count = 0;
            text = name + '\n' + '0笔';
            result[0] = text;
            result[1] = count;
            return result;
        } else {

            var result = [];
            var text = []
            for (var i = 0; i < list.length; i++) {
                var item = list[i];
                var zone = null;
                if (item.zoneNumber == null) {
                    zone = item.communityId
                } else {
                    zone = item.zoneNumber;
                }
                if (zoneNumber == zone) {
                    count = item.count;
                    text = name + '\n' + item.count + '笔';
                    result[0] = text;
                    result[1] = count;
                    break;
                } else {
                    count = 0;
                    text = name + '\n' + '0笔';
                    result[0] = text;
                    result[1] = count;
                }
            }
            return result;
        }
    },
    getCenter: function (id) {
        var cityId = id.substring(0, 2);
        var center = null;
        var url = '../../assets/newMap/data/mapdata/city/' + cityId + '.json';
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            success: function (data) {
                data.features.forEach(function (item) {
                    if (id == (item.properties.id + '00')) {
                        center = ol.proj.transform(item.properties.cp, 'EPSG:4326', 'EPSG:3857');
                        return;
                    }
                });
                if (center == null) {
                    center = ol.proj.transform(data.cp, 'EPSG:4326', 'EPSG:3857');
                }
            }
        })
        return center;
    },
    createDiv:function(paramsData) {
        var resultList = new Array();
        var tmpList = new Array();
        var resultList, topDiv, sj, lastSmall, oneSmall;
        paramsData.forEach(function (searchEstate) {
            var div = document.createElement("div");
            searchEstate.forEach(function (data, i) {
                //自定义楼栋覆盖物
                var smallDiv;
                if (i != 0) {
                    if (oneSmall) oneSmall.style.padding = "6px 18px 6px 10px";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.estateList.length + '笔'));
                    smallDiv.style.padding = "6px 18px 6px 10px";
                    smallDiv.style.borderRadius = '8px';
                    smallDiv.style.marginLeft = '-10px';
                    if (data.estateList[0].define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                    } else if (data.estateList[0].define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                    } else if (data.estateList[0].define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                    } else if (data.estateList[0].define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                    }
                    lastSmall = smallDiv;
                    topDiv.appendChild(smallDiv);
                } else {
                    if (lastSmall) lastSmall.style.padding = '6px 10px';

                    div.style.position = "absolute";
                    div.style.color = "white";
                    div.style.opacity = '0.95';
                    div.style.display = 'flex';
                    div.style.whiteSpace = "nowrap";
                    div.style.MozUserSelect = "none";
                    div.style.fontSize = "12px";
                    div.style.cursor = "pointer";
                    smallDiv = document.createElement('div');
                    smallDiv.appendChild(document.createTextNode(data.estateList.length + '笔'));
                    smallDiv.style.padding = "6px 10px";
                    smallDiv.style.borderRadius = "8px";
                    div.appendChild(smallDiv);
                    sj = this._p = document.createElement("p");
                    if (data.estateList[0].define == '中风险') {
                        smallDiv.style.backgroundColor = "#FF9800";
                        sj.style.borderTop = "10px solid #FF9800";
                    } else if (data.estateList[0].define == '低风险') {
                        smallDiv.style.backgroundColor = "#62CB31";
                        sj.style.borderTop = "10px solid #62CB31";
                    } else if (data.estateList[0].define == '高风险') {
                        smallDiv.style.backgroundColor = "#E51C23";
                        sj.style.borderTop = "10px solid #E51C23";
                    } else if (data.estateList[0].define == '亏损') {
                        smallDiv.style.backgroundColor = "#8B1818";
                        sj.style.borderTop = "10px solid #8B1818";
                    }
                    sj.style.position = "absolute";
                    sj.style.width = 0;
                    sj.style.height = 0;
                    sj.style.borderLeft = "10px solid transparent";
                    sj.style.borderRight = "10px solid transparent";
                    sj.style.bottom = "-20px";
                    sj.style.left = '6px';
                    div.appendChild(sj);
                    oneSmall = smallDiv;
                    lastSmall = null;
                    topDiv = div;
                }
                topDiv.onclick = function () {
                    $(this).parent().siblings().children().children("div.row").css("display", "none");
                    $(this).parent().siblings().children().css('zIndex', 'auto');
                    $(this).css('zIndex', '11')
                    $(this).children('div.row').toggle();
                    if ($(this).children('div.row').length >= 1) return;
                    var listDiv = document.createElement("div");
                    listDiv.style.position = 'absolute';
                    listDiv.style.left = this.offsetWidth + 14 + "px";
                    listDiv.style.color = '#6a6c6f';
                    listDiv.style.width = '400px';
                    listDiv.style.whiteSpace = 'normal';
                    listDiv.className = 'row';
                    var col = document.createElement("div");
                    var hpanel = document.createElement("div");
                    hpanel.className = 'hpanel';
                    var hpanelHead = document.createElement("div");
                    hpanelHead.className = 'panel-heading hbuilt';
                    hpanelHead.onclick = function (e) {
                        e.stopPropagation()
                    };
                    var panelTools = document.createElement('div');
                    panelTools.className = 'panel-tools';
                    var closebox = document.createElement('a');
                    var closeIcon = document.createElement('i');
                    closeIcon.className = 'fa fa-times';
                    closebox.appendChild(closeIcon);
                    closebox.className = 'closebox';
                    var that = $(this);
                    closebox.onclick = function () {
                        that.children("div.row").css("display", "none");
                    };
                    panelTools.appendChild(closebox);
                    hpanelHead.appendChild(panelTools);
                    hpanelHead.appendChild(document.createTextNode(data.estateList[0].communityname));
                    var hpanelBody = document.createElement("div");
                    hpanelBody.className = 'panel-body no-padding';
                    hpanelBody.style.maxHeight = '190px';
                    hpanelBody.style.overflowY = 'auto';
                    var listGroup = document.createElement('ul');
                    listGroup.className = 'list-group';
                    var hpanelFoot = document.createElement('div');
                    hpanelFoot.className = 'panel-footer';
                    hpanelBody.appendChild(listGroup);
                    hpanel.appendChild(hpanelHead);
                    hpanel.appendChild(hpanelBody);
                    hpanel.appendChild(hpanelFoot);
                    col.appendChild(hpanel);
                    listDiv.appendChild(col);
                    this.appendChild(listDiv);
                    searchEstate.forEach(function (data) {
                        var itemData = data.estateList;
                        itemData.forEach(function (data) {
                            var item = document.createElement('li');
                            item.className = 'list-group-item ';
                            var badge = document.createElement('span');
                            badge.className = 'badge badge-info';
                            badge.innerHTML = data.cltv + '%';
                            item.appendChild(badge);
                            if (data.define == '中风险') {
                                badge.style.backgroundColor = "#FF9800";
                            } else if (data.define == '低风险') {
                                badge.style.backgroundColor = "#62CB31";
                            } else if (data.define == '高风险') {
                                badge.style.backgroundColor = "#E51C23";
                            } else if (data.define == '亏损') {
                                badge.style.backgroundColor = "#8B1818";
                            }
                            item.appendChild(document.createTextNode(data.sourceaddress));
                            item.onclick = function () {
                                var href = window.location.origin + "/estate/mapShow/" + data.id;
                                window.open(href);
                            };
                            listGroup.appendChild(item);
                        });
                    });
                    var listLength = listGroup.children.length;
                    hpanelFoot.innerHTML = '共 ' + listLength + ' 笔';
                };
            });
            tmpList = new Array();
            tmpList[0] = topDiv;
            tmpList[1] =[searchEstate[0].lng,searchEstate[0].lat];
            resultList.push(tmpList);
        });
        return resultList;
    },
    createRightDiv: function (name,hourseCount) {
        var div = this._div = document.createElement("div");
        var img = document.createElement('img');
        img.src = '/assets/accountLogo/zhoubian.png';
        div.style.position = "absolute";
        div.style.cursor = 'pointer';
        div.style.zIndex = '1';
        var message = document.createElement('div');
        message.style.position = 'absolute';
        message.style.border = '1px solid rgb(98, 203, 49)';
        message.style.background = '#fff';
        message.style.borderRadius = '6px';
        message.style.width = '230px';
        message.style.height = '50px';
        message.style.top = '-60px';
        message.style.left = '-98px';
        message.style.textAlign = 'center';
        var header = document.createElement('h5');
        header.innerHTML = name;
        header.style.fontWeight = 'bold';
        message.appendChild(header);
        var body = document.createElement('p');
        body.innerHTML = '已押总量<strong style="color: red;">' +jump.rqInfoCount+ '笔' + '</strong> / 总户数<strong style="color: rgb(98, 203, 49);"> '+hourseCount+'</strong>';
        message.appendChild(body);
        var sj = this._p = document.createElement("p");
        sj.style.position = "absolute";
        sj.style.width = 0;
        sj.style.height = 0;
        sj.style.borderLeft = "10px solid transparent";
        sj.style.borderRight = "10px solid transparent";
        sj.style.bottom = "-20px";
        sj.style.left = '105px';
        sj.style.borderTop = "10px solid #FF9000";
        message.appendChild(sj);
        div.appendChild(message);
        div.appendChild(img);
        img.onclick = function () {
            $(this).siblings('div').toggle();
        };
        return div;
    },
    aroundPointDiv: function (community) {
        console.log(community)
        var div = this._div = document.createElement("div");
        var icon = document.createElement('img');
        if (community.isEstate == 'true') {
            icon.src = '/assets/accountLogo/icon.png';
        } else {
            icon.src = '/assets/accountLogo/isicon.png';
        }
        icon.onclick = function () {
            location.href = location.origin + '/estate/searchEstate?buildingId=' + Community.buildingId + '&isEstate=' + Community.isEstate + '&communityId=' + accountId;
        };
        div.appendChild(icon);
        div.style.position = "absolute";
        div.style.cursor = "pointer";
        // map.getPanes().labelPane.appendChild(div);
        return div;
    },
    hiddenOverly: function () {
        var eleOverlys = $('.ol-overlay-container.ol-selectable');
        for (var i = 0; i < eleOverlys.length; i++) {
            var div = eleOverlys[i];
            var dis = div.style.display;
            if (dis != 'none') {
                div.style.display = 'none';
            }
        }
    },
    showOverly: function () {
        var eleOverlys = $('.ol-overlay-container.ol-selectable');
        for (var i = 0; i < eleOverlys.length; i++) {
            var div = eleOverlys[i];
            var dis = div.style.display;
            if (dis != 'block') {
                div.style.display = 'block';
            }
        }
    },
    createPopup: function () {
        var container = document.getElementById('popup');
        this.popup = new ol.Overlay({
            id: 'popup',
            element: container,
            autoPan: true,
            offset: [-50, 30],
            positioning: 'bottom-right',
            autoPanAnimation: {
                duration: 250
            }
        });
        map.addOverlay(this.popup);
    },
    showInfo:function (point,name,count) {
        var container = document.getElementById('popup');
        var content = document.getElementById('popup-content');
        content.innerHTML =
            '<div>' + name + '</div>' +
            '<div>押品数量:' + count + ' 笔</div>';
        container.style.display = 'block';
        this.popup.setPosition(point);
    },
    clearOverly:function () {
        var overlys = map.getOverlays();
        overlys.forEach(function (overly) {
            if (overly != null && overly.id != 'popup') {
                map.removeOverlay(overly)
            }
        })

    },
    getColorForId: function (id,size) {
        var color = 'rgba(76, 160, 101, 0.9)';
        switch (id) {
            case 'province': {
                color = 'rgba(76, 160, 101, 0.9)';
            }
                break;
            case 'city': {
                if (size > 700) {
                    color = "#26b095";
                } else if (size > 500) {
                    color = "#33c3a7"
                } else if (size > 300) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
            case 'county': {
                if (size > 700) {
                    color = "#26b095";
                } else if (size > 500) {
                    color = "#33c3a7"
                } else if (size > 300) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
            case 'rq': {
                if (size > 15) {
                    color = "#26b095";
                } else if (size > 10) {
                    color = "#33c3a7"
                } else if (size > 5) {
                    color = "#4cdcc0";
                } else {
                    color = "#79ecd6";
                }
            }
                break;
        }
        return color;
    }
}